package vn.mahjonggame.metadata;

import java.util.Collection;
import java.util.List;

import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSArray;
import com.smartfoxserver.v2.entities.data.SFSObject;

public class Response {
	private final SFSObject mObject;
	private final StringBuffer strBuff;
	
	private Response(Builder builder){
		this.mObject = builder.mObject;
		this.strBuff = builder.strBuff;	
	}
	
	@Override
	public String toString(){
		return this.strBuff.toString();
	}
	
	public SFSObject getSFSObject(){
		return this.mObject;
	}
	
	public static class Builder {
		private final SFSObject mObject;
		private final StringBuffer strBuff;
		
		public Builder() {
			this.mObject = new SFSObject();;
			this.strBuff = new StringBuffer();
		}
		
		public Builder tile(int tileId){
			this.mObject.putInt(MObject.tile.toString(), tileId);
			this.strBuff.append(MObject.tile.toString()).append(tileId).append("|");
			return this;
		}
		
		public Builder position(int position){
			this.mObject.putInt(MObject.position.toString(), position);
			this.strBuff.append(MObject.position.toString()).append(position).append("|");
			return this;
		}
		
		public Builder nextPosition(int nextPosition){
			this.mObject.putInt(MObject.nextPosition.toString(), nextPosition);
			this.strBuff.append(MObject.nextPosition.toString()).append(nextPosition).append("|");
			return this;
		}
		
		public Builder turn(int turn){
			this.mObject.putInt(MObject.turn.toString(), turn);
			this.strBuff.append(MObject.turn.toString()).append(turn).append("|");
			return this;
		}
		
		public Builder preTurn(int preTurn){
			this.mObject.putInt(MObject.preTurn.toString(), preTurn);
			this.strBuff.append(MObject.preTurn.toString()).append(preTurn).append("|");
			return this;
		}
		
		public Builder isAuto(boolean isAuto){
			this.mObject.putBool(MObject.isAuto.toString(), isAuto);
			this.strBuff.append(MObject.isAuto.toString()).append(isAuto).append("|");
			return this;
		}
		
		public Builder isConflict(boolean isConflict){
			this.mObject.putBool(MObject.isConflict.toString(), isConflict);
			this.strBuff.append(MObject.isConflict.toString()).append(isConflict).append("|");
			return this;
		}
		
		public Builder type(String type){
			if(type != null){
				this.mObject.putUtfString(MObject.type.toString(), type);
				this.strBuff.append(MObject.type.toString()).append(type).append("|");
			}			
			return this;
		}
		
		public Builder kanType(String kanType){
			if(kanType != null){
				this.mObject.putUtfString(MObject.kanType.toString(), kanType);
				this.strBuff.append(MObject.kanType.toString()).append(kanType).append("|");
			}			
			return this;
		}
		
		public Builder type(int type){
			this.mObject.putInt(MObject.type.toString(), type);
			this.strBuff.append(MObject.type.toString()).append(type).append("|");
			return this;
		}
		
		public Builder isWait(boolean isWait){
			this.mObject.putBool(MObject.isWait.toString(), isWait);
			this.strBuff.append(MObject.isWait.toString()).append(isWait).append("|");
			return this;
		}
		
		public Builder doras(Collection<Integer> doras){
			this.mObject.putIntArray(MObject.doras.toString(), doras);
			this.strBuff.append(MObject.doras.toString()).append(doras).append("|");
			return this;
		}
		
		public Builder dora(int dora){
			this.mObject.putInt(MObject.dora.toString(), dora);
			this.strBuff.append(MObject.dora.toString()).append(dora).append("|");
			return this;			
		}
		
		public Builder dice1(int dice1){
			this.mObject.putInt(MObject.dice1.toString(), dice1);
			this.strBuff.append(MObject.dice1.toString()).append(dice1).append("|");
			return this;
		}
		
		public Builder dice2(int dice2){
			this.mObject.putInt(MObject.dice2.toString(), dice2);
			this.strBuff.append(MObject.dice2.toString()).append(dice2).append("|");
			return this;
		}
		
		public Builder players(SFSArray players){
			this.mObject.putSFSArray(MObject.players.toString(), players);
			this.strBuff.append(MObject.players.toString()).append(players).append("|");
			return this;
		}
		
		public Builder tiles(Collection<Integer> tiles){
			this.mObject.putIntArray(MObject.tiles.toString(), tiles);
			this.strBuff.append(MObject.tiles.toString()).append(tiles).append("|");
			return this;
		}
		
		public Builder lefttiles(List<Integer> lefttiles){
			this.mObject.putIntArray(UserVarName.lefttiles.toString(), lefttiles);
			this.strBuff.append(UserVarName.lefttiles.toString()).append(lefttiles).append("|");
			return this;
		}
		
		public Builder lefttilesInOrder(List<Integer> lefttilesInOrder){
			this.mObject.putIntArray(UserVarName.lefttilesInOrder.toString(), lefttilesInOrder);
			this.strBuff.append(UserVarName.lefttilesInOrder.toString()).append(lefttilesInOrder).append("|");
			return this;
		}
		
		public Builder point(double point){
			this.mObject.putDouble(MObject.point.toString(), point);
			this.strBuff.append(MObject.point.toString()).append(point).append("|");
			return this;
		}
		
		public Builder money(double money){
			this.mObject.putDouble(MObject.money.toString(), money);
			this.strBuff.append(MObject.money.toString()).append(money).append("|");
			return this;
		}
		
		public Builder isWinner(boolean isWinner){
			this.mObject.putBool(MObject.isWinner.toString(), isWinner);
			this.strBuff.append(MObject.isWinner.toString()).append(isWinner).append("|");
			return this;
		}
		
		public Builder bonusTime(int bonusTime){
			this.mObject.putInt(MObject.bonusTime.toString(), bonusTime);
			this.strBuff.append(MObject.bonusTime.toString()).append(bonusTime).append("|");
			return this;
		}
		
		public Builder chiTiles(Collection<Integer> chiTiles){
			this.mObject.putIntArray(MObject.chiTiles.toString(), chiTiles);
			this.strBuff.append(MObject.chiTiles.toString()).append(chiTiles).append("|");
			return this;
		}
		
		public Builder turnTime(int turnTime){
			this.mObject.putInt(MObject.turnTime.toString(), turnTime);
			this.strBuff.append(MObject.turnTime.toString()).append(turnTime).append("|");
			return this;
		}
		
		public Builder winPos(int winPos){
			this.mObject.putInt(MObject.winPos.toString(), winPos);
			this.strBuff.append(MObject.winPos.toString()).append(winPos).append("|");
			return this;
		}
		
		public Builder winPos(Collection<Integer> winPos){
			this.mObject.putIntArray(MObject.winPos.toString(), winPos);
			this.strBuff.append(MObject.winPos.toString()).append(winPos).append("|");
			return this;
		}
		
		public Builder losePos(int losePos){
			this.mObject.putInt(MObject.losePos.toString(), losePos);
			this.strBuff.append(MObject.losePos.toString()).append(losePos).append("|");
			return this;
		}
		
		public Builder winTile(List<Integer> winTile){
			this.mObject.putIntArray(MObject.winTile.toString(), winTile);
			this.strBuff.append(MObject.winTile.toString()).append(winTile).append("|");
			return this;
		}
		
		public Builder winTile(int winTile){
			this.mObject.putInt(MObject.winTile.toString(), winTile);
			this.strBuff.append(MObject.winTile.toString()).append(winTile).append("|");
			return this;
		}
		
		public Builder winTile(SFSArray winTile){
			this.mObject.putSFSArray(MObject.winTile.toString(), winTile);
			this.strBuff.append(MObject.winTile.toString()).append(winTile).append("|");
			return this;
		}
		
		public Builder loseTile(int loseTile){
			this.mObject.putInt(MObject.loseTile.toString(), loseTile);
			this.strBuff.append(MObject.loseTile.toString()).append(loseTile).append("|");
			return this;
		}
		
		public Builder message(String message){
			this.mObject.putUtfString(MObject.message.toString(), message);
			this.strBuff.append(MObject.message.toString()).append(message).append("|");
			return this;
		}
		
		public Builder name(String name){
			this.mObject.putUtfString(MObject.name.toString(), name);
			this.strBuff.append(MObject.name.toString()).append(name).append("|");
			return this;
		}
		
		public Builder avatar(String avatar){
			this.mObject.putUtfString(MObject.avatar.toString(), avatar);
			this.strBuff.append(MObject.avatar.toString()).append(avatar).append("|");
			return this;
		}
		
		public Builder user_id(String user_id){
			this.mObject.putUtfString(UserVarName.user_id.toString(), user_id);
			this.strBuff.append(UserVarName.user_id.toString()).append(user_id).append("|");
			return this;
		}
		
		public Builder users(SFSArray sfsUserArray){
			this.mObject.putSFSArray(MObject.users.toString(), sfsUserArray);
			this.strBuff.append(MObject.users.toString()).append(sfsUserArray).append("|");
			return this;
		}
		
		public Builder id(int id){
			this.mObject.putInt(MObject.id.toString(), id);
			this.strBuff.append(MObject.id.toString()).append(id).append("|");
			return this;
		}
		
		public Builder isItMe(boolean isItMe){
			this.mObject.putBool(MObject.isItMe.toString(), isItMe);
			this.strBuff.append(MObject.isItMe.toString()).append(isItMe).append("|");
			return this;
		}
		
		public Builder amount(double amount){
			this.mObject.putDouble(UserVarName.amount.toString(), amount);
			this.strBuff.append(UserVarName.amount.toString()).append(amount).append("|");
			return this;
		}
		
		public Builder HOA(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.HOA.toString(), mObject);
			this.strBuff.append(TileSet.HOA.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder RON(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.RON.toString(), mObject);
			this.strBuff.append(TileSet.RON.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder RIICHI(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.RIICHI.toString(), mObject);
			this.strBuff.append(TileSet.RIICHI.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder OPENKAN(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.OPENKAN.toString(), mObject);
			this.strBuff.append(TileSet.OPENKAN.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder LATEKAN(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.LATEKAN.toString(), mObject);
			this.strBuff.append(TileSet.LATEKAN.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder CLOSEKAN(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.CLOSEKAN.toString(), mObject);
			this.strBuff.append(TileSet.CLOSEKAN.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder PON(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.PON.toString(), mObject);
			this.strBuff.append(TileSet.PON.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder CHI(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.CHI.toString(), mObject);
			this.strBuff.append(TileSet.CHI.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder TSUMO(ISFSObject mObject){
			this.mObject.putSFSObject(TileSet.TSUMO.toString(), mObject);
			this.strBuff.append(TileSet.TSUMO.toString()).append(mObject).append("|");
			return this;
		}
		
		public Builder actor(String actor){
			this.mObject.putUtfString(MObject.actor.toString(), actor);
			this.strBuff.append(MObject.actor.toString()).append(actor).append("|");
			return this;			
		}
		
		public Builder actor_displayname(String actor_displayname){
			this.mObject.putUtfString(MObject.actor_displayname.toString(), actor_displayname);
			this.strBuff.append(MObject.actor_displayname.toString()).append(actor_displayname).append("|");
			return this;			
		}
		
		public Builder action(String action){
			this.mObject.putUtfString(MObject.action.toString(), action);
			this.strBuff.append(MObject.action.toString()).append(action).append("|");
			return this;			
		}
		
		public Builder param_1(String param_1){
			this.mObject.putUtfString(MObject.param_1.toString(), param_1);
			this.strBuff.append(MObject.param_1.toString()).append(param_1).append("|");
			return this;			
		}
		
		public Builder param_2(String param_2){
			this.mObject.putUtfString(MObject.param_2.toString(), param_2);
			this.strBuff.append(MObject.param_2.toString()).append(param_2).append("|");
			return this;			
		}
		
		public Builder timestamp(String timestamp){
			this.mObject.putUtfString(MObject.timestamp.toString(), timestamp);
			this.strBuff.append(MObject.timestamp.toString()).append(timestamp).append("|");
			return this;			
		}
		
		public Response build(){
			Response response = new Response(this);
			return response;
		}
	}
}
